package com.jjh.web;

import com.jjh.Application;
import com.jjh.util.UserThreadLocal;
import com.jjh.util.ViewUtils;
import com.jjh.web.controller.ShopController;
import com.jjh.web.controller.UserController;
import com.jjh.web.view.ShopView;
import com.jjh.web.view.UserView;
import com.jjh.winterframework.annatation.Autowired;
import com.jjh.winterframework.annatation.Component;
import com.jjh.winterframework.core.ApplicationContext;

import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * 菜单功能
 * @author JJH
 */

public class Menu {



    private static Scanner sc = new Scanner(System.in);

   public static void show(){

       UserController userController =
               (UserController) ApplicationContext.GetBean(UserController.class);

        boolean flag = true;
        System.out.println("<================================== 欢迎来到 饿了么 点餐平台 " +
                "================================>");
        System.out.println("----------------------请 选 择 功 能:");
        while (flag){
            System.out.println("  ->  1.用 户 登 录");
            System.out.println("  ->  2.用 户 注 册");
            System.out.println("  ->  0.退 出 系 统");

            int ch = 0;
            try {
                ch = sc.nextInt();
            } catch (InputMismatchException e) {
                System.out.println("输入错误，请重新输入！");
                sc.nextLine();
            }

            switch (ch){
                case 1:
                    userController.login();
                    flag = false;
                    break;
                case 2:
                    userController.register();
                   flag = false;
                    break;
                case 0:
                    flag = false;
                    break;
                default:
                    System.out.println("输入错误，请重新选择！");
                    break;
            }

        }

    }

    /**
     * 子菜单一
     */
   public static void subMenu01(){
       ShopController shopController =
               (ShopController) ApplicationContext.GetBean(ShopController.class);
       UserController userController =
               (UserController) ApplicationContext.GetBean(UserController.class);
       boolean flag = true;
        System.out.println("<===================================== 系 统 功 能 ========================" +
                "=================>");
        while (flag){
            System.out.println("  -> 1.点 餐");
            System.out.println("  -> 2.个 人 界 面");
            System.out.println("  -> 0.退 出");
            switch (sc.nextInt()){
                case 1:
                    shopController.showShop();
                    flag = false;
                    break;
                case 2:
                    userController.UserInfo();
                    break;
                case 0:
                    flag =false;
                    break;
                default:
                    System.out.println("======>输入错误! 请重新输入:");
                    break;
            }
        }
     }




}
